package org.etnaframework.module.localcache;

import org.springframework.data.redis.connection.RedisConnectionFactory;

/**
 * Type2类型的缓存（定时全量重新加载 + 检查点全量更新）
 *
 * @author jasyaf
 * @since 2023-11-01
 */
public class LocalCacheType2<T> implements ILocalCache<T> {

    private final LocalCacheCore<T> localCacheCore;

    @Override
    public T get() {
        return localCacheCore.get();
    }

    LocalCacheType2(String name, String scheduledFullUpdateCron, long timeoutSec, RedisConnectionFactory redisConnectionFactory, int checkpointUpdateIntervalSec, ILocalCacheCustomizer<T> customizer) {
        localCacheCore = new LocalCacheCore<>(name, scheduledFullUpdateCron, timeoutSec, customizer, null, redisConnectionFactory, checkpointUpdateIntervalSec);
        localCacheCore.start();
    }

    /**
     * 标记【全量】更新事件，注意更新是后台异步执行的（调用完该方法后再调{@link #get()}并不会立即有变化），该操作同步到所有的运行实例
     */
    public void markFullUpdate() {
        localCacheCore.markFullUpdate();
    }
}
